package com.qfmy.controller.user;

import com.qfmy.service.user.UserInfoService;
import com.qfmy.vo.user.UserInfoVo;
import common.result.Result;
import jakarta.annotation.Resource;
import model.annotation.LogAnnotation;
import model.query.LoginQuery;
import model.query.UserInfoQuery;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 清风明月
 * @Package com.qfmy.controller
 * @date 2025/5/17
 * @description 用户信息
 */
@RestController
@RequestMapping("/app")
@SuppressWarnings("all")
public class UserInfoController {

    /**
     * 注入service
     */
    @Resource
    private UserInfoService userInfoService;

    /**
     * 获取短信验证码
     */
    @RequestMapping("/userInfo/getSmsCode")
    public Result getSmsCode(@RequestParam String phone) {
        userInfoService.getSmsCode(phone);
        return Result.ok();
    }

    /**
     * 登录
     */
    @LogAnnotation(operation = "登录")
    @RequestMapping("/userInfo/login")
    public Result login(@RequestBody LoginQuery loginQuery) {
        String token = userInfoService.login(loginQuery);
        return Result.ok(token);
    }

    /**
     * 注册
     */
    @LogAnnotation(operation = "注册")
    @RequestMapping("/userInfo/register")
    public Result register(@RequestBody LoginQuery loginQuery) {
        userInfoService.register(loginQuery);
        return Result.ok();
    }
    /**
     * 找回密码
     */
    @LogAnnotation(operation = "找回密码")
    @RequestMapping("/userInfo/findPassword")
    public Result findPassword(@RequestBody LoginQuery loginQuery) {
        userInfoService.findPassword(loginQuery);
        return Result.ok();
    }

    /**
     * 获取用户信息
     */
    @RequestMapping("/getUserInfo")
    public Result<UserInfoVo> getUserInfo() {
        UserInfoVo userInfoVo = userInfoService.getUserInfo();
        return Result.ok(userInfoVo);
    }

    /**
     * 修改用户信息
     */
    @RequestMapping("/updateUserInfo")
    public Result updateUserInfo(@RequestBody UserInfoQuery userInfoQuery) {
        userInfoService.updateUserInfo(userInfoQuery);
        return Result.ok();
    }

    /**
     * 更新用户头像
     */
    @RequestMapping("/updateUserAvatar")
    public Result updateUserAvatar(@RequestParam String avatar) {
        userInfoService.updateUserAvatar(avatar);
        return Result.ok();
    }

    /**
     * 获取用户的二维码
     */
    @RequestMapping("/getUserQrCode")
    public Result getUserQrCode() {
        String qrCode = userInfoService.getUserQrCode();
        return Result.ok(qrCode);
    }

    /**
     * 设置喜欢的小说类型
     */
    @RequestMapping("/setLikeNovelType")
    public Result setLikeNovelType(@RequestParam String name) {
        userInfoService.setLikeNovelType(name);
        return Result.ok();
    }

    /**
     * 保存用户阅读时间
     */
    @RequestMapping("/saveUserReadTime")
    public Result saveUserReadTime(@RequestParam Long time) {
        userInfoService.saveUserReadTime(time);
        return Result.ok();
    }

}
